﻿using System;
using System.Linq;
using System.Windows.Controls;

namespace EasySL.Controls
{
    public partial class ExDataGrid : DataGrid
    {
        private void BindDeleteEvent(ExCommandPanel cp)
        {
            cp.OnDelete += (bindProperty) =>
            {                
                foreach (ExDataGridColumn c in this.Columns)
                {
                    if (c != null && c.BindProperty == bindProperty)
                    {                       
                        this.Dispatcher.BeginInvoke(() =>
                        {
                            this.Columns.Remove(c);
                        });
                        break; 
                    }
                }

                foreach (ExCommandPanel p in this.CommandPanels)
                {
                    if (p != null && p.BindProperty == bindProperty)
                    {
                        this.CommandPanels.Remove(p);
                        break;
                    }
                }

                foreach (ExDropLocation l in this.DropLocations)
                {
                    if (l != null && l.BindProperty == bindProperty)
                    {
                        this.DropLocations.Remove(l);
                        break;
                    }
                }
            };
        }
    }
}
